package com.fuchuang.seckillsystem.rocketmq;

import com.fuchuang.seckillsystem.service.IOrderService;
import com.fuchuang.seckillsystem.vo.SeckillMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(nameServer = "${rocketmq.name-server}", topic = "seckill",
        consumerGroup = "create-order-group", selectorExpression = "create", selectorType = SelectorType.TAG)
public class CreateOrderConsumer implements RocketMQListener<SeckillMessage> {
    
    @Autowired
    private IOrderService orderService;
    
    @Override
    public void onMessage(SeckillMessage message) {
        log.info("收到创建订单消息：{}", message);
        //生成订单
        orderService.createSeckillOrder(message);
    }
}